// pages/zxactivity/zxactivity.js
var app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getactivityslist: app.data.url +'/zhongxue/maoapi/getactivityslist',
    page:1,
    shuju:[],
    srcd: app.data.url +"/uploads/zhongxue/lou.png",
    huodongs:[
      {
        src: app.data.url +"/uploads/zhongxue/huodongs.png", title: "博知堂 - 做颠覆传统教育的“野蛮人” ......",xuexiao:"成都校区",cishu:"125",date:"2017-10-16"},

      {
        src: app.data.url +"/uploads/zhongxue/huodongs.png", title: "博知堂 - 做颠覆传统教育的“野蛮人” ......", xuexiao: "成都校区", cishu: "125", date: "2017-10-16"
      },

      {
        src: app.data.url +"/uploads/zhongxue/huodongs.png", title: "博知堂 - 做颠覆传统教育的“野蛮人” ......", xuexiao: "成都校区", cishu: "125", date: "2017-10-16"
      },
    ]
  },
  //点击图片进入详情
  xqss:function(e){
    // console.log(e);
    var id = e.currentTarget.dataset.id;
    var shuju = this.data.shuju;
    var user = wx.getStorageSync('user');
    var that = this;
    ea.each(shuju,function(i,v){
      if (parseInt(v.id) ==parseInt(id)){
        if(v.url){
          wx.setStorageSync('urls', v.url)
          wx.showLoading({
            title: '加载中',
            mask: true,
          })
          wx.request({
            url: that.data.getactivityslist,
            data: {token:user.token,id:id},
            header: {},
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: function(res) {
              wx.hideLoading();
              var data = res.data;
              if(data.code==200){
                wx.navigateTo({
                  url: '/pages/webview/webview',
                })
              }else{
                wx.showToast({
                  title: data.msg,
                  icon:'none',
                  duration: app.data.quanbushijian
                })
              }
            },
            fail: function(res) {},
            complete: function(res) {},
          })
        }
      }
    })


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getData:function(){
    var page = this.data.page;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration: app.data.quanbushijian
      })
      return
    }
    var that = this;
    var user = wx.getStorageSync("user");
    wx.showLoading({
      title: '加载中',
    })
    var campus = wx.getStorageSync('xiaoqu');
    console.log(campus);
    wx.request({
      url: that.data.getactivityslist,
      data: { token: user.token, page: page, campus: campus},
      method:'post',
      success:function(res){
        var data = res.data;
        console.log(data);
        if(data.code==200){
          var shuju = that.data.shuju;
          var newshuju = data.data;
          if(newshuju.length<10){
            that.setData({page:0});
          }else{
            that.setData({page:page+1})
          };
          ea.each(newshuju,function(i,v){
            shuju.push(v);
          })
          // console.log(shuju);
          that.setData({shuju:shuju});
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian
          })
        }
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({page:1,shuju:[]});
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})